AddUser = {
	saveConfig:function (){
		var username = document.getElementById("username").value;
		var realName = document.getElementById("realName").value;
		var password = document.getElementById("password").value;
		var tel = document.getElementById("tel").value;
		var email = document.getElementById("email").value;
		
		var user = document.getElementsByName('existname');
		for(var i=0;i<user.length;i++){
		    var k = user[i].value;
		    if(username==k){
		        PigossMsg.alert("同名用户已存在");
		        return;
		    }
		}
		if(username==0||username==''){
		   PigossMsg.alert("用户名不能为空或者空格");
		   return;
		}
		if(realName==0||realName==''){
		   PigossMsg.alert("真实姓名不能为空或者空格");
		   return;
		}
		if(password==0||password==''){
		   PigossMsg.alert("密码不能为空或者空格");
		   return;
		}
		if(tel !=""){
		    var isExit = false;
			var partten = /^0(([1-9]\d)|([3-9]\d{2}))\d{8}$/;
		    if (partten.test(tel)) {
		        alert("llll");
		        isExit = true;	
		    } 
			var rules = /^1[3,5]\d{9}$/;
		    if(/^13\d{9}$/g.test(tel)||(/^15[0-35-9]\d{8}$/g.test(tel))||(/^18[05-9]\d{8}$/g.test(tel))){     
	             isExit = true;
		    }
		    
		    if(!isExit){
		       PigossMsg.alert("联系方式不是手机或电话号码！");
			   return;
		    }
		}
		if(email !=""){
		    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (!(filter.test(email))){ 
			    PigossMsg.alert("您的电子邮件格式不正确！");
			    return;
			}
		}
		AjaxUtil.request({
			url : 'add_user.action',
			params : {username:username,realName:realName,password:password,tel:tel,email:email},
			success :function(responseText){
				RefreshUser.refresh();
			},
			failure : function(){
				PigossMsg.alert("添加失败！");
			}
		});
		imgCloseShow();
	}
};

RefreshUser= {
	   refresh:function(){
	       document.getElementById("findAllUser").submit();
	   }
};

EditUser= {
    editConfig:function (){
		
		var id = document.getElementById("id").value;
		var username = document.getElementById("username").value;
		var realName = document.getElementById("realName").value;
		var tel = document.getElementById("tel").value;
		var email = document.getElementById("email").value;
		if(username==0||username==''){
		   PigossMsg.alert("用户名不能为空或者空格！");
		   return;
		}
		if(realName==0||realName==''){
		   PigossMsg.alert("真实姓名不能为空或者空格！");
		   return;
		}
		
		if(tel !=""){
		    var isExit = false;
			var partten = /^0(([1-9]\d)|([3-9]\d{2}))\d{8}$/;
		    if (partten.test(tel)) {
		        alert("llll");
		        isExit = true;
		    } 
			var rules = /^1[3,5]\d{9}$/;
		    if(/^13\d{9}$/g.test(tel)||(/^15[0-35-9]\d{8}$/g.test(tel))||(/^18[05-9]\d{8}$/g.test(tel))){     
	             isExit = true;
		    }
		    
		    if(!isExit){
		       PigossMsg.alert("联系方式不是手机或电话号码！");
			   return;
		    }
		}
		if(email !=""){
		    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (!(filter.test(email))){ 
			    PigossMsg.alert("您的电子邮件格式不正确！");
			    return;
			}
		}
		
		AjaxUtil.request({
			url : 'editsave_user.action',
			params : {id:id,username:username,realName:realName,tel:tel,email:email},
			success : function(responseText){
				RefreshUser.refresh();
			},
			failure : function(){
				 PigossMsg.alert("修改失败!");
			}
		});
		imgCloseShow();	
	},
	
	del:function (id){
	    AjaxUtil.request({
			url : 'delete_user.action',
			params : {id:id},
			success : function(responseText){
				RefreshUser.refresh();
			},
			failure : function(){
				PigossMsg.alert("删除失败!");
			}
		});
	}
};

//用户修改密码
EditPassword= {
    editPasswordConfig:function (){
		
		var id = document.getElementById("id").value;
		var oldpassword = document.getElementById("oldpassword").value;
		var newpassword = document.getElementById("newpassword").value;
		var renewpassword = document.getElementById("renewpassword").value;
		
		var editUserPassword = document.getElementById("editUserPassword").value;
		var StringOldPassword = hex_md5(oldpassword);
		
		if(editUserPassword != StringOldPassword){
			PigossMsg.alert("原始密码不正确！");
			return;
		}
		if(oldpassword ==''){
		   PigossMsg.alert("原密码不能为空！");
		   return;
		}
		if(newpassword ==''){
		   PigossMsg.alert("新密码不能为空！");
		   return;
		}
		if(renewpassword ==''){
		   PigossMsg.alert("再次输入的密码不能为空！");
		   return;
		}
		
		if(newpassword != renewpassword){
		   PigossMsg.alert("两次输入的新密码不符！");
		   return;
		}

		
		
		AjaxUtil.request({
			url : 'user_editPassword.action',
			params : {id:id,newpassword:newpassword,oldpassword:oldpassword},
			success : function(responseText){
				RefreshUser.refresh();
			     /*var result = decode(responseText);
			     if(result.success){
			    	 RefreshUser.refresh();
                   }else{
                       PigossMsg.alert("修改失败！");
                   }*/
			},
			failure : function(){
				 PigossMsg.alert("修改失败！");
			}
		});
		
	}
};

//admin修改密码
EditPasswordAdmin= {
    editPasswordConfig:function (){
		var id = document.getElementById("id").value;
		var newpassword = document.getElementById("newpassword").value;
		if(newpassword ==''){
		   PigossMsg.alert("密码不能为空！");
		   return;
		}

		AjaxUtil.request({
			url : 'user_editPasswordAdmin.action',
			params : {id:id,newpassword:newpassword},
			success : function(responseText){
                       imgCloseShow();	
                       window.location.reload();
			},
			failure : function(){
				 PigossMsg.alert("修改密码失败!");
			}
		});
		
	}
};

